<?php
/**
 * Created by PhpStorm.
 * User: lwt
 * Date: 4/25/19
 * Time: 8:31 PM
 */
 
namespace app\admin\model;

use think\Db;
use think\Model;

class CodeModel extends Model
{
    public static function addBatchParentCode($data){
        $request = Db::table('tb_parent_code')->insertAll($data);
        return $request;
    }

    public static function addBatchSubCode($data){
        $request = Db::table('tb_subcode')->insertAll($data);
        return $request;
    }

    public static function selectAllParentCode($data){
        $msg = Db::query('select *  from tb_parent_code where co_id = ? order by pc_id DESC limit ?',[$data["co_id"],$data["num"]]);
        return $msg;
    }

    public static function selectAllSubCode($pc_id){
        $msg = Db::query('select *  from tb_subcode where pc_id = ?',[$pc_id]);
        return $msg;
    }

    public static function selectCommodityById($pc_id){
        $msg = Db::query('select *  from tb_parent_code where pc_id = ?',[$pc_id]);
        $msg1 = BatchModel::selectBatchByCoId($msg[0]["co_id"]);
        $msg2 = CommodityModel::selectCommodityById($msg1[0]["cos_id"]);
        return $msg2;
    }
}